package com.example.concurrent;

public class Singleton {
	private Singleton() {
		
	}
	//懒惰实例化
	private static volatile Singleton INSTANCE = null;
	public static Singleton getInstance() {
		//首次访问会同步，而之后使用不会加锁
		//原子性，有序性，可见性
		if(INSTANCE == null) {
			synchronized (Singleton.class) {
				if (INSTANCE == null) {
					INSTANCE = new Singleton();
				}
			}
		}
		return INSTANCE;
	}
}
